﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace Services.Equ
{
    /// <summary>
    /// 设备相关的常量
    /// </summary>
    public class ConstParameters
    {
        public static readonly PhysicalAddress SearchDstMac = PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF");
        public static readonly string SearchFliter = "ether proto 0xf1f1";
        public static readonly int TimeOut = 5;
        public static readonly byte[] SearchPayload = [0xFE, 0xFE, 0x05, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x04, 0xff, 0xff, 0x00, 0x00];
        public static readonly byte[] CustomerType = [0xf1, 0xf1];
        /// <summary>
        /// 获取搜索设备报文方法
        /// </summary>
        /// <param name="srcMac"></param>
        /// <returns></returns>
        public static byte[] GetSearchHeader(PhysicalAddress srcMac)
        {
            return GetHeader(srcMac, SearchDstMac);
        }
        public static byte[] GetHeader(PhysicalAddress srcMac, PhysicalAddress desMac)
        {
            var srcByte = srcMac.GetAddressBytes();
            var desByte = desMac.GetAddressBytes();
            var header = new byte[srcByte.Length + desByte.Length + CustomerType.Length];
            for (int i = 0; i < desByte.Length; i++)
            {
                header[i] = desByte[i];
            }
            for (int i = 0; i < srcByte.Length; i++)
            {
                header[i + desByte.Length] = srcByte[i];
            }
            for (int i = 0; i < CustomerType.Length; i++)
            {
                header[i + desByte.Length + srcByte.Length] = CustomerType[i];
            }
            return header;
        }
        public static byte[] GetSearchHeader(string srcMacStr)
        {
            var srcMac= PhysicalAddress.Parse(srcMacStr);
            return GetSearchHeader(srcMac);
        }
    }
}
